<?php
//require_once IPOST_FRAMEWORK_PATH . 'settings_base.php';
//require_once IPOST_FRAMEWORK_PATH . 'settings-ui.php';
//$theme_settings = new ThemeSettings();
//$theme_settings->initialize(IPOST_THEME_JS_URL, IPOST_THEME_CSS_URL);
/* Save/Reset actions | Adds theme options to WP-Admin menu */

add_action('admin_menu', 'ipost_add_to_admin_menu');

function ipost_add_to_admin_menu() {
    global $themename;
    $epanel = basename(__FILE__);

    if (isset($_GET['page']) && $_GET['page'] == $epanel && isset($_REQUEST['action'])) {
        epanel_save_data('js_disabled'); //saves data when javascript is disabled
    }

    $core_page = add_theme_page($themename . " Options", "Theme Options", 'switch_themes', basename(__FILE__), 'build_ipost_panel');
    add_action("admin_print_scripts-{$core_page}", 'ipost_panel_admin_js');

    add_action("admin_head-{$core_page}", 'ipost_panel_css_admin');
}

if (!function_exists('build_ipost_panel')) {

    function build_ipost_panel() {
        global $themename, $ipt_options;
        if (isset($_REQUEST['saved'])) {
            if ($_REQUEST['saved'])
                echo '<div id="message" class="updated fade"><p><strong>' . $themename . ' settings saved.</strong></p></div>';
        };
        if (isset($_REQUEST['reset'])) {
            if ($_REQUEST['reset'])
                echo '<div id="message" class="updated fade"><p><strong>' . $themename . ' settings reset.</strong></p></div>';
        };
        ?>        
        <div id="admin_main_pane">            
            <div class="admin-panel-ctl row">
                <div id="of_nav_pane">
                    <ul class="list-option-menu">
                        <li class="logo">SETTINGS</li>
        <?php
        foreach ($ipt_options as $option_name => $option) {
            ?>
                            <li name="left-menu-nav" id="<?php echo $option_name ?>nav" content-id="<?php echo $option_name ?>" class="<?php echo $option_name ?>-nav <?php echo $option['icon'] ?>">
                                <a title="Home Settings"> <?php echo $option['name'] ?></a>
                            </li> 
                            <li class="seperator"></li>
            <?php
        }
        ?>
                    </ul>
                </div>
                <div id="of_content_pane">
                    <div class="toolbar">
                        <div class="paddingRight">
                            <img style="display:none" src="<?php echo IPOST_THEME_IMG_URL ?>/images/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working...">
                            <input type="hidden" id="security" name="security">	
                            <button id="of_save_top" type="button" class="btn btn-primary">Save All Changes</button>
                        </div>
                    </div>
                    <div id="content-pane">
                        <form class="forms">
                            <?php
                            foreach ($ipt_options as $option_name => $option) {
                                ?>
                                <div id="<?php echo $option_name ?>-content" class="left-content" style="display:none">
                                    <ul>
                                        <?php
                                        foreach ($option['options'] as $option_value => $option_data) {
                                            $type = $option_data['type'];
                                            $name = $option_data['name'];
                                            $id = $option_data['id'];
                                            $desc = $option_data['desc'];
                                            $std = $option_data['std'];
                                            //BEGIN SWITCH
                                            switch ($type) {
                                                case 'text':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>
                                                        <input type="text" placeholder="Type <?php echo $name ?>…" id="<?php echo $id ?>" name="<?php echo $id ?>" value="<?php echo $std ?>" class="seven input-gray" size="60"/>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                                case 'textarea':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>                                     
                                                        <textarea placeholder="Type <?php echo $name ?>…" id="<?php echo $id ?>" name="<?php echo $id ?>" class="seven input-gray" cols="8"><?php echo $std ?></textarea>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                                case 'select':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>                                     
                                                        <select id="<?php echo $id ?>" name="<?php echo $id ?>">

                                                        </select>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                                case 'upload':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>                                     
                                                        <input type="file" id="<?php echo $id ?>" name="<?php echo $id ?>"/>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                                case 'checklist':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>                                     
                                                        <input type="file" id="<?php echo $id ?>" name="<?php echo $id ?>"/>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                                case 'tab':
                                                    ?>
                                                    <li>
                                                        <label for="<?php echo $id ?>" class="bold"><?php echo $name ?></label>                                     
                                                        <input type="text" id="<?php echo $id ?>" name="<?php echo $id ?>"/>
                                                        <div class="help-block font11"><?php echo $desc ?></div>
                                                    </li>   
                                                    <?php
                                                    break;
                                            } //END SWITCH
                                        }
                                        ?>
                                    </ul>
                                </div>
                                <?php
                            }
                            ?>                    
                        </form>
                    </div>
                    <div class="toolbar bottom">
                        <div class="paddingRight">
                            <img style="display:none" src="<?php echo IPOST_THEME_IMG_URL ?>/images/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working...">                            
                            <button id="of_save_bottom" type="button" class="btn btn-primary">Save All Changes</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <?php
    }

}

global $pagenow;
if ('themes.php' == $pagenow && isset($_GET['page']) && ($_GET['page'] == basename(__FILE__))) {
    add_action('admin_print_scripts', 'ipost_media_upload_scripts');
    add_action('admin_print_styles', 'ipost_media_upload_styles');
}
?>
